<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:output method="text" indent="no" encoding="utf-8" omit-xml-declaration="yes" />
  <xsl:strip-space elements="*" />
  <xsl:preserve-space elements="xsl:text" />
  <xsl:param name="controlName" />
  <xsl:template match="//class" name="class">
    <xsl:for-each select="controls//control">
      <xsl:variable name="type" select="@type" />
      <xsl:variable name="ctrlName" select="@name" />
      <xsl:choose>
        <xsl:when test="($type='Ext.grid.GridPanel' or $type='Ext.grid.EditorGridPanel') and not(@render='false')">
          <xsl:call-template name="Table" />
        </xsl:when>
        <xsl:when test="$type='NetJsWire.ComboBox'">
          <xsl:call-template name="Combo" />
        </xsl:when>
        <xsl:when test="$type='Ext.tree.TreePanel' and not(@render='false')">
          <xsl:call-template name="TreePanel" />
        </xsl:when>
        <xsl:when test="$type='Ext.TabPanel' and not(@render='false')">
          <xsl:call-template name="TabPanel" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:if test="not(@render='false')">
            <xsl:call-template name="Control" />
          </xsl:if>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:for-each select="propertys//property">
        <xsl:call-template name="Property">
          <xsl:with-param name="controlName" select="$ctrlName" />
        </xsl:call-template>
      </xsl:for-each>
      <xsl:for-each select="equalpropertys//equalproperty">
        <xsl:call-template name="EqualProperty">
          <xsl:with-param name="controlName" select="$ctrlName" />
        </xsl:call-template>
      </xsl:for-each>
      <xsl:for-each select="code/codeline">
        <xsl:value-of select="." />
      </xsl:for-each>
      <xsl:for-each select="events/event">
        <xsl:value-of select="." />
      </xsl:for-each>
    </xsl:for-each>
    <xsl:for-each select="code/codeline">
      <xsl:value-of select="." />
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="Control" match="control" xml:space="default">
    <xsl:choose>
      <xsl:when test="@type='{}'">
        <xsl:value-of select="@name" />
        <xsl:text>={};</xsl:text>
      </xsl:when>
      <xsl:when test="@type='Ext.Viewport'">
        <xsl:value-of select="@name" />
        <xsl:text>=new</xsl:text>
        <xsl:value-of select="@type" />
        <xsl:text>
          ({monitorResize:true,layout:'absolute'});
        </xsl:text>
      </xsl:when>
      <xsl:when test="@type='Ext.Button'">
        <xsl:value-of select="@name" />
        <xsl:text>= new</xsl:text>
        <xsl:value-of select="@type" />
        <xsl:text>({</xsl:text>
        <xsl:call-template name="ConfigOptions" />
        <xsl:text>});</xsl:text>
      </xsl:when>
      <xsl:when test="@type='Ext.form.Checkbox'">
        <xsl:text>
          var _divEltmp = Ext.DomHelper.append(
        </xsl:text>
        <xsl:value-of select="@parent" />
        <xsl:text>, {tag:'div',</xsl:text>
        <xsl:call-template name="Styles" />
        <xsl:text>});</xsl:text>
        <xsl:value-of select="@name" />
        =new
        <xsl:value-of select="@type" />
        ({
        <xsl:call-template name="ConfigOptionsNoStyle" />
        <xsl:text>});</xsl:text>
      </xsl:when>
      <xsl:when test="@type='Ext.form.TextField' or @type='Ext.form.DateField' or @type='Ext.form.NumberField'">
        <xsl:value-of select="@name" />
        =new
        <xsl:value-of select="@type" />
        ({
        <xsl:call-template name="ConfigOptions" />
        <xsl:text>});</xsl:text>
      </xsl:when>
      <xsl:when test="@type='Ext.form.FieldSet'">
        <xsl:value-of select="@name" />
        = new
        <xsl:value-of select="@type" />
        ({
        <xsl:call-template name="ConfigOptions" />
        });
      </xsl:when>
      <xsl:when test="@type='Ext.Toolbar'">
        <xsl:variable name="name" select="@name" />
        <xsl:value-of select="@name" />
        = new
        <xsl:value-of select="@type" />
        ({
        <xsl:call-template name="ConfigOptions" />
        <xsl:text>});</xsl:text>
      </xsl:when>
      <xsl:when test="@type='Ext.Panel'">
        <xsl:choose>
          <xsl:when test="@isLayout='true'">
            <xsl:value-of select="@name" />
            = new
            <xsl:value-of select="@type" />
            ({
            <xsl:call-template name="ConfigOptions" />
            <xsl:text>,items:[</xsl:text>
            <xsl:for-each select="items//item">
              <xsl:text>new</xsl:text>
              <xsl:value-of select="@type" />
              <xsl:text>({id:'</xsl:text>
              <xsl:value-of select="@name" />
              <xsl:text>',region:'</xsl:text>
              <xsl:value-of select="@region" />
              <xsl:text>',title:'</xsl:text>
              <xsl:value-of select="@title" />
              <xsl:text>',width:</xsl:text>
              <xsl:value-of select="@width" />
              <xsl:text>,height:</xsl:text>
              <xsl:value-of select="@height" />
              <xsl:text>,collapsible:</xsl:text>
              <xsl:value-of select="@collapsible" />
              <xsl:text>,split:</xsl:text>
              <xsl:value-of select="@split" />
              <xsl:text>,layout:'</xsl:text>
              <xsl:value-of select="@layout" />
              <xsl:text>',useIFrame:</xsl:text>
              <xsl:value-of select="@useIframe" />
              <xsl:text>,url:'</xsl:text>
              <xsl:value-of select="@url" />
              <xsl:text>'})</xsl:text>
              <xsl:if test="not(position()=last())">,</xsl:if>
            </xsl:for-each>
            <xsl:text>]});</xsl:text>
            <xsl:for-each select="items//item">
              <xsl:value-of select="@name" />
              <xsl:text>=Ext.getCmp('</xsl:text>
              <xsl:value-of select="@name" />
              <xsl:text>');</xsl:text>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:choose>
              <xsl:when test="@useIframe='true'">
                <xsl:value-of select="@name" />
                = new NetJsWire.Panel('
                <xsl:value-of select="@name" />
                ', {
                <xsl:call-template name="ConfigOptions" />
                ,url:'
                <xsl:value-of select="@url" />
                <xsl:text>',useIFrame:true });</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="@name" />
                = new
                <xsl:value-of select="@type" />
                ({
                <xsl:call-template name="ConfigOptions" />
                <xsl:text>});</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="@isInLayout='true'">
          <xsl:value-of select="@parent" />
          .add(
          <xsl:value-of select="@name" />
          <xsl:text>);</xsl:text>
          <xsl:value-of select="@parent" />
          <xsl:text>.doLayout();</xsl:text>
        </xsl:if>
        <xsl:value-of select="@name" />
        <xsl:text>.syncSize();</xsl:text>
      </xsl:when>
      <xsl:when test="@type='Ext.menu.Separator'">
        <xsl:value-of select="@parent" />
        <xsl:text>.add('-');</xsl:text>
      </xsl:when>
      <xsl:when test="@type='Ext.Toolbar.Button'">
        <xsl:if test="@hasItems='true'">
          <xsl:value-of select="@name" />
          <xsl:text>
            _Menu=new Ext.menu.Menu({id:'
          </xsl:text>
          <xsl:value-of select="@name" />
          <xsl:text>_Menu'});</xsl:text>
        </xsl:if>
        <xsl:value-of select="@name" />
        =new
        <xsl:value-of select="@type" />
        ({
        <xsl:call-template name="ConfigOptionsNoStyle" />
        <xsl:if test="@hasItems='true'">
          ,menu:
          <xsl:value-of select="@name" />
          _Menu
        </xsl:if>
        <xsl:text>});</xsl:text>
        <xsl:value-of select="@parent" />
        .add(
        <xsl:value-of select="@name" />
        <xsl:text>);</xsl:text>
      </xsl:when>
      <xsl:when test="@type='Ext.menu.Item'">
        <xsl:if test="@hasItems='true'">
          <xsl:value-of select="@name" />
          <xsl:text>
            _Menu=new Ext.menu.Menu({id:'
          </xsl:text>
          <xsl:value-of select="@name" />
          <xsl:text>_Menu'});</xsl:text>
        </xsl:if>
        <xsl:value-of select="@name" />
        =
        <xsl:value-of select="@menu" />
        .add(new
        <xsl:value-of select="@type" />
        ({
        <xsl:call-template name="ConfigOptionsNoStyle" />
        <xsl:if test="@hasItems='true'">
          ,menu:
          <xsl:value-of select="@name" />
          _Menu
        </xsl:if>
        <xsl:text>}));</xsl:text>
      </xsl:when>
      <xsl:when test="@type='Ext.form.FormPanel'">
        <xsl:value-of select="@name" />
        = new
        <xsl:value-of select="@type" />
        ({
        <xsl:call-template name="ConfigOptionsPx" />
        });
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@name" />
        = new
        <xsl:value-of select="@type" />
        ("
        <xsl:value-of select="@id" />
        ",{
        <xsl:call-template name="ConfigOptions" />
        });
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="TreePanel">
    <xsl:variable name="name" select="@name" />
    <xsl:text>
      var _divEltmp=Ext.DomHelper.append(
    </xsl:text>
    <xsl:value-of select="@parent" />
    <xsl:text>,{tag:'div',</xsl:text>
    <xsl:call-template name="Styles" />
    <xsl:text>});</xsl:text>
    <xsl:value-of select="@name" />
    <xsl:text>=new</xsl:text>
    <xsl:value-of select="@type" />
    <xsl:text>
      ({frame:true,el:_divEltmp,
    </xsl:text>
    <xsl:call-template name="ConfigOptionsNoStyle" />
    <xsl:text>});</xsl:text>
    <xsl:text>var _rootNode;</xsl:text>
    <xsl:for-each select="nodes//node">
      <xsl:choose>
        <xsl:when test="@root='true'">
          <xsl:text>
            _rootNode=new Ext.tree.TreeNode({text:'
          </xsl:text>
          <xsl:value-of select="@text" />
          <xsl:text>',id:'</xsl:text>
          <xsl:value-of select="@name" />
          <xsl:text>',draggable:false</xsl:text>
          <xsl:if test="@qtip!=''">
            ,qtip:'
            <xsl:value-of select="@qtip" />
            '
          </xsl:if>
          <xsl:if test="@qtipCfg!=''">
            ,qtipCfg:
            <xsl:value-of select="@qtipCfg" />
          </xsl:if>
          <xsl:text>});</xsl:text>
        </xsl:when>
        <xsl:when test="@parent != ''">
          <xsl:text>var</xsl:text>
          <xsl:value-of select="@name" />
          =
          <xsl:value-of select="@parent" />
          .appendChild(new Ext.tree.TreeNode({ text:'
          <xsl:value-of select="@text" />
          ', id:'
          <xsl:value-of select="@name" />
          '
          <xsl:if test="@qtip!=''">
            ,qtip:'
            <xsl:value-of select="@qtip" />
            '
          </xsl:if>
          <xsl:if test="@qtipCfg!=''">
            ,qtipCfg:
            <xsl:value-of select="@qtipCfg" />
          </xsl:if>
          <xsl:text>}));</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>var</xsl:text>
          <xsl:value-of select="@name" />
          = _rootNode.appendChild(new Ext.tree.TreeNode({ text:'
          <xsl:value-of select="@text" />
          ', id:'
          <xsl:value-of select="@name" />
          '
          <xsl:if test="@qtip!=''">
            ,qtip:'
            <xsl:value-of select="@qtip" />
            '
          </xsl:if>
          <xsl:if test="@qtipCfg!=''">
            ,qtipCfg:
            <xsl:value-of select="@qtipCfg" />
          </xsl:if>
          <xsl:text>}));</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
    <xsl:value-of select="@name" />
    <xsl:text>
      .setRootNode(_rootNode);
    </xsl:text>
    <xsl:value-of select="@name" />
    <xsl:text>.render();</xsl:text>
  </xsl:template>

  <xsl:template name="TabPanel">
    <xsl:variable name="name" select="@name" />
    <xsl:value-of select="@name" />
    = new
    <xsl:value-of select="@type" />
    ({
    <xsl:call-template name="ConfigOptions" />
    <xsl:text>});</xsl:text>
    <xsl:for-each select="pages//page">
      <xsl:value-of select="$name" />
      .
      <xsl:value-of select="@name" />
      =
      <xsl:value-of select="$name" />
      .add({title: '
      <xsl:value-of select="@text" />
      '
      <xsl:if test="@toolTip!=''">
        ,tabTip:'
        <xsl:value-of select="@toolTip" />
        '
      </xsl:if>
      <xsl:text>
        ,layout:'absolute',style:{width:'100%',height:'100%'}});
      </xsl:text>
      <xsl:value-of select="$name" />
      .
      <xsl:value-of select="@name" />
      <xsl:text>.show();</xsl:text>
    </xsl:for-each>
    <xsl:value-of select="$name" />
    .activate(
    <xsl:value-of select="@selected" />
    <xsl:text>);</xsl:text>
    <xsl:value-of select="@name" />
    <xsl:text>.syncSize();</xsl:text>
  </xsl:template>

  <xsl:template name="Combo">
    <xsl:variable name="parent" select="@parent" />
    <xsl:variable name="width" select="@width" />
    <xsl:if test="@render='true'">
      <xsl:value-of select="@name" />
      <xsl:text>=new</xsl:text>
      <xsl:value-of select="@type" />
      <xsl:text>('</xsl:text>
      <xsl:value-of select="@name" />
      <xsl:text>', {</xsl:text>
      <xsl:call-template name="ConfigOptions" />
      <xsl:text>,data:</xsl:text>
      <xsl:text>[</xsl:text>
      <xsl:for-each select="data//chunk">
        <xsl:text>[</xsl:text>
        <xsl:value-of select="." />
        <xsl:text>]</xsl:text>
        <xsl:if test="not(position()=last())">,</xsl:if>
      </xsl:for-each>
      <xsl:text>]</xsl:text>
      <xsl:text>, parent:</xsl:text>
      <xsl:value-of select="$parent" />
      <xsl:text>});</xsl:text>
    </xsl:if>
    <xsl:if test="not(@render='true')">
      <xsl:value-of select="@name" />
      <xsl:text>.store.loadData([</xsl:text>
      <xsl:for-each select="data//chunk">
        <xsl:text>[</xsl:text>
        <xsl:value-of select="." />
        <xsl:text>]</xsl:text>
        <xsl:if test="not(position()=last())">,</xsl:if>
      </xsl:for-each>
      <xsl:text>]);</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template name="Property">
    <xsl:param name="controlName" />
    <xsl:variable name="type" select="@type" />
    <xsl:value-of select="$controlName" />
    .
    <xsl:value-of select="@name" />
    (
    <xsl:if test="$type='string'">"</xsl:if>
    <xsl:value-of select="@value" />
    <xsl:if test="$type='string'">"</xsl:if>
    <xsl:text>);</xsl:text>
  </xsl:template>

  <xsl:template name="EqualProperty">
    <xsl:value-of select="." />
    <!--<xsl:value-of select="$controlName"/>.<xsl:value-of select="@name"/>=<xsl:if test="$type='string'">"</xsl:if><xsl:value-of select="@value"/><xsl:if test="$type='string'">"</xsl:if>;-->
  </xsl:template>

  <xsl:template name="Event">
    <xsl:param name="controlName" />
    <xsl:value-of select="." />
  </xsl:template>

  <xsl:template name="ConfigOptions">
    <xsl:for-each select="options//option">
      <xsl:variable name="type" select="@type" />
      <xsl:value-of select="@name" />
      <xsl:text>:</xsl:text>
      <xsl:if test="@name='top'">'</xsl:if>
      <xsl:if test="@name='left'">'</xsl:if>
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:value-of select="@value" />
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:if test="@name='top'">'</xsl:if>
      <xsl:if test="@name='left'">'</xsl:if>
      <xsl:if test="not(position()=last())">,</xsl:if>
    </xsl:for-each>
    <xsl:text>,style:{</xsl:text>
    <xsl:for-each select="options//styles//style">
      <xsl:variable name="type" select="@type" />
      <xsl:value-of select="@name" />
      <xsl:text>:</xsl:text>
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:value-of select="@value" />
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:if test="not(position()=last())">,</xsl:if>
    </xsl:for-each>
    <xsl:text>}</xsl:text>
  </xsl:template>

  <xsl:template name="ConfigOptionsPx">
    <xsl:for-each select="options//option">
      <xsl:variable name="type" select="@type" />
      <xsl:value-of select="@name" />
      :
      <xsl:if test="@name='width'">'</xsl:if>
      <xsl:if test="@name='height'">'</xsl:if>
      <xsl:if test="@name='top'">'</xsl:if>
      <xsl:if test="@name='left'">'</xsl:if>
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:value-of select="@value" />
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:if test="@name='width'">px'</xsl:if>
      <xsl:if test="@name='height'">px'</xsl:if>
      <xsl:if test="@name='top'">px'</xsl:if>
      <xsl:if test="@name='left'">px'</xsl:if>
      <xsl:if test="not(position()=last())">,</xsl:if>
    </xsl:for-each>
    <xsl:text>,style:{</xsl:text>
    <xsl:for-each select="options//styles//style">
      <xsl:variable name="type" select="@type" />
      <xsl:value-of select="@name" />
      :
      <xsl:if test="@name='width'">'</xsl:if>
      <xsl:if test="@name='height'">'</xsl:if>
      <xsl:if test="@name='top'">'</xsl:if>
      <xsl:if test="@name='left'">'</xsl:if>
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:value-of select="@value" />
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:if test="@name='width'">px'</xsl:if>
      <xsl:if test="@name='height'">px'</xsl:if>
      <xsl:if test="@name='top'">px'</xsl:if>
      <xsl:if test="@name='left'">px'</xsl:if>
      <xsl:if test="not(position()=last())">,</xsl:if>
    </xsl:for-each>
    <xsl:text>}</xsl:text>
  </xsl:template>

  <xsl:template name="ConfigOptionsNoStyle">
    <xsl:for-each select="options//option">
      <xsl:variable name="type" select="@type" />
      <xsl:value-of select="@name" />
      :
      <xsl:if test="@name='top'">'</xsl:if>
      <xsl:if test="@name='left'">'</xsl:if>
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:value-of select="@value" />
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:if test="@name='top'">'</xsl:if>
      <xsl:if test="@name='left'">'</xsl:if>
      <xsl:if test="not(position()=last())">,</xsl:if>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="Styles">
    <xsl:text>style:{</xsl:text>
    <xsl:for-each select="options//styles//style">
      <xsl:variable name="type" select="@type" />
      <xsl:value-of select="@name" />
      <xsl:text>:</xsl:text>
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:value-of select="@value" />
      <xsl:if test="$type='string'">"</xsl:if>
      <xsl:if test="not(position()=last())">,</xsl:if>
    </xsl:for-each>
    <xsl:text>}</xsl:text>
  </xsl:template>

  <xsl:template name="Table" xml:space="default">
    <xsl:variable name="remoteSort" select="@remoteSort" />
    <xsl:variable name="id" select="@id" />
    <xsl:if test="@useGroupSummary='true'">
      <xsl:text>
        var summary=new Ext.grid.GroupSummary();
      </xsl:text>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="@remoteLoad='true'">
        <xsl:choose>
          <xsl:when test="@groupBy!=''">
            <xsl:text>
              var _ds = new Ext.data.GroupingStore({
            </xsl:text>
            <xsl:if test="$remoteSort='true'">
              <xsl:text>remotesort:true,</xsl:text>
            </xsl:if>
            <xsl:text>groupField:'</xsl:text>
            <xsl:value-of select="@groupBy" />
            <xsl:text>',</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>
              var _ds=new Ext.data.Store({
            </xsl:text>
            <xsl:if test="$remoteSort='true'">remotesort:true,</xsl:if>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>
          baseParams:{service:'GridDataService',method:'RequestGridData',Id:'
        </xsl:text>
        <xsl:value-of select="@id" />
        <xsl:text>'},</xsl:text>
        <xsl:text>
          proxy: new Ext.data.HttpProxy({url:'webapp/
        </xsl:text>
        <xsl:value-of select="@id" />
        <xsl:text>
          .ashx'}),reader:new Ext.data.JsonReader({id:0,totalProperty:'totalCount',root:'results'},
        </xsl:text>
        <xsl:text>[{name:"RI"},</xsl:text>
        <xsl:for-each select="columns//column">
          <xsl:text>{name:'</xsl:text>
          <xsl:value-of select="@name" />
          <xsl:text>',mapping:'</xsl:text>
          <xsl:value-of select="@name" />
          <xsl:text>'}</xsl:text>
          <xsl:if test="not(position()=last())">,</xsl:if>
        </xsl:for-each>
        <xsl:text>])});</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="griddata" />
        <xsl:choose>
          <xsl:when test="@groupBy!=''">
            <xsl:text>
              var _ds = new Ext.data.GroupingStore({id:0,
            </xsl:text>
            <xsl:if test="$remoteSort='true'">remotesort:true,</xsl:if>
            <xsl:text>groupField:'</xsl:text>
            <xsl:value-of select="@groupBy" />
            <xsl:text>',sortInfo:{field:'</xsl:text>
            <xsl:value-of select="@groupBy" />
            <xsl:text>
              ', direction: 'ASC'}, reader: new Ext.data.ArrayReader({id:"RI"},[{name:"RI"},
            </xsl:text>
            <xsl:for-each select="columns//column">
              <xsl:text>{name:'</xsl:text>
              <xsl:value-of select="@name" />
              <xsl:text>'}</xsl:text>
              <xsl:if test="not(position()=last())">,</xsl:if>
            </xsl:for-each>
            <xsl:text>])});</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>
              var _ds = new Ext.data.Store({
            </xsl:text>
            <xsl:if test="$remoteSort='true'">remotesort:true,</xsl:if>
            <xsl:text>
              reader: new Ext.data.ArrayReader({id:0},[{name:"RI"},
            </xsl:text>
            <xsl:for-each select="columns//column">
              <xsl:text>{name:'</xsl:text>
              <xsl:value-of select="@name" />
              <xsl:text>'}</xsl:text>
              <xsl:if test="not(position()=last())">,</xsl:if>
            </xsl:for-each>
            <xsl:text>])});</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>
          _ds.loadData(gridData);
        </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>
      var cm=new Ext.grid.ColumnModel([{id:'RI',header:'Row Index',dataIndex:'RI',hidden:true},
    </xsl:text>
    <xsl:for-each select="columns//column">
      <xsl:text>{header:'</xsl:text>
      <xsl:value-of select="@header" />
      <xsl:text>',dataIndex:'</xsl:text>
      <xsl:value-of select="@name" />
      <xsl:text>',width:</xsl:text>
      <xsl:value-of select="@width" />
      <xsl:if test="@css!=''">
        <xsl:text>,css:'</xsl:text>
        <xsl:value-of select="@css" />
        <xsl:text>'</xsl:text>
      </xsl:if>
      <xsl:if test="@align!=''">
        <xsl:text>,align:'</xsl:text>
        <xsl:value-of select="@align" />
        <xsl:text>'</xsl:text>
      </xsl:if>
      <xsl:if test="@renderer!=''">
        <xsl:text>,renderer:</xsl:text>
        <xsl:value-of select="@renderer" />
      </xsl:if>
      <xsl:if test="@hidden!=''">
        <xsl:text>,hidden:</xsl:text>
        <xsl:value-of select="@hidden" />
      </xsl:if>
      <xsl:if test="@editable!=''">
        <xsl:text>,editable:</xsl:text>
        <xsl:value-of select="@editable" />
      </xsl:if>
      <xsl:if test="@editor!=''">
        <xsl:text>,editor:</xsl:text>
        <xsl:value-of select="@editor" />
      </xsl:if>
      <xsl:if test="@summaryType!=''">
        <xsl:text>,summaryType:'</xsl:text>
        <xsl:value-of select="@summaryType" />
        <xsl:text>'</xsl:text>
      </xsl:if>
      <xsl:if test="@summaryRenderer!=''">
        <xsl:text>,summaryRenderer:</xsl:text>
        <xsl:value-of select="@summaryRenderer" />
      </xsl:if>
      <xsl:if test="@sortable!=''">
        <xsl:text>,sortable:</xsl:text>
        <xsl:value-of select="@sortable" />
      </xsl:if>
      <xsl:if test="@tooltip!=''">
        <xsl:text>,tooltip:'</xsl:text>
        <xsl:value-of select="@tooltip" />
        <xsl:text>'</xsl:text>
      </xsl:if>
      <xsl:text>}</xsl:text>
      <xsl:if test="not(position()=last())">,</xsl:if>
    </xsl:for-each>
    <xsl:text>]);</xsl:text>
    <xsl:variable name="name" select="@name" />
    <xsl:variable name="type" select="@type" />
    <xsl:variable name="remoteLoad" select="@remoteLoad" />
    <xsl:variable name="grouping" select="@groupBy" />
    <xsl:variable name="viewTpl" select="@groupTextTpl" />
    <xsl:variable name="frame" select="@frame" />
    <xsl:choose>
      <xsl:when test="@renderMethod='normal'">
        <xsl:for-each select="div">
          <xsl:value-of select="$name" />
          <xsl:text>=new</xsl:text>
          <xsl:value-of select="$type" />
          <xsl:text>({renderTo:</xsl:text>
          <xsl:value-of select="@parent" />
          <xsl:text>
            ,ds:_ds,cm:cm,enableColumnHide:false,enableHdMenu:true,frame:
          </xsl:text>
          <xsl:value-of select="$frame" />
          <xsl:text>,width:</xsl:text>
          <xsl:value-of select="@width" />
          <xsl:text>,height:</xsl:text>
          <xsl:value-of select="@height" />
          <xsl:text>
            , style:{position:'relative',left:'
          </xsl:text>
          <xsl:value-of select="@left" />
          <xsl:text>px',top:'</xsl:text>
          <xsl:value-of select="@top" />
          <xsl:text>
            px'},monitorResize:true,anchor:'
          </xsl:text>
          <xsl:value-of select="@anchor" />
          <xsl:text>'</xsl:text>
        </xsl:for-each>
        <xsl:if test="@autoExpandColumn!=''">
          ,autoExpandColumn:'
          <xsl:value-of select="@autoExpandColumn" />
          '
        </xsl:if>
        <xsl:if test="@useGroupSummary='true'">,plugins:summary</xsl:if>
        <xsl:if test="$remoteLoad='true'">
          ,bbar:new Ext.PagingToolbar({pageSize:25,store:_ds,displayInfo:true,displayMsg:'Mostrando registros {0} - {1} de {2}',emptyMsg:'No hay registros'})
        </xsl:if>
        <xsl:if test="$grouping!=''">
          ,view:new Ext.grid.GroupingView({forceFit:true,groupTextTpl:'
          <xsl:value-of select="$viewTpl" />
          '
          <xsl:if test="@startCollapsed='true'">
            ,startCollapsed: true
          </xsl:if>
          })
        </xsl:if>
        <xsl:text>});</xsl:text>
      </xsl:when>
      <xsl:when test="@renderMethod='InfoPanel'">
        <xsl:for-each select="div">
          var _divEltmp = Ext.DomHelper.append(
          <xsl:value-of select="@parent" />
          , {id:"
          <xsl:value-of select="$name" />
          _panel", name:"
          <xsl:value-of select="$name" />
          _panel", tag: "div", style:{position:'relative',left:'
          <xsl:value-of select="@left" />
          px', top:'
          <xsl:value-of select="@top" />
          px', width:'
          <xsl:value-of select="@width" />
          px', height:'
          <xsl:value-of select="@height" />
          px', overflow:'hidden'} });
        </xsl:for-each>
        <xsl:value-of select="@name" />
        = new Ext.grid.GridPanel({applyTo:_divEltmp, ds: _ds,cm: cm, enableColumnHide:false});
        <xsl:for-each select="div">
          <xsl:value-of select="@parent" />
          .on({ resize: { scope:
          <xsl:value-of select="$name" />
          , fn: function() { Ext.get('
          <xsl:value-of select="$name" />
          _panel').fitToParent();
          <xsl:value-of select="$name" />
          .autoSize();} } });
        </xsl:for-each>
        <xsl:value-of select="@name" />
        .render();
      </xsl:when>
      <xsl:when test="@renderMethod='Panel'">
        <xsl:for-each select="div">
          var _divEltmp = Ext.DomHelper.append(
          <xsl:value-of select="@parent" />
          , {id:"
          <xsl:value-of select="$name" />
          _panel", name:"
          <xsl:value-of select="$name" />
          _panel", tag: "div", style:{position:'relative',left:'
          <xsl:value-of select="@left" />
          px', top:'
          <xsl:value-of select="@top" />
          px', width:'
          <xsl:value-of select="@width" />
          px', height:'
          <xsl:value-of select="@height" />
          px', overflow:'hidden'} });
          var _divGridEltmp = Ext.DomHelper.append(_divEltmp, {id:"
          <xsl:value-of select="$name" />
          _Grid", name:"
          <xsl:value-of select="$name" />
          _Grid", tag: "div", overflow:'hidden'});
        </xsl:for-each>
        <xsl:value-of select="@name" />
        = new Ext.grid.RefreshingGrid(_divGridEltmp, {ds: ds,cm: cm, enableColumnHide:false});
        <xsl:value-of select="@name" />
        .render();
      </xsl:when>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="@remoteLoad='true'">
        <xsl:text>
          _ds.load({params:{start:0,limit:25}});
        </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <!--_ds.load();-->
      </xsl:otherwise>
    </xsl:choose>
    <!--<xsl:value-of select="tabPageFix"/>-->
  </xsl:template>

</xsl:stylesheet>